#pragma once
#include"RBTree_with_iterator.h"

namespace RoundBottle
{
	template<class K, class V>
	struct KeyofMap
	{
		const K& operator()(const pair<const K, V>& data)
		{
			return data.first;
		}
	};

	template<class K, class V>
	class map
	{
	public:
		typedef typename RBTree<pair<const K, V>, KeyofMap<K, V>>::iterator iterator;
		typedef typename RBTree<pair<const K, V>, KeyofMap<K, V>>::const_iterator const_iterator;


		iterator begin() { return _rb.Begin(); }
		iterator end() { return _rb.End(); }

		const_iterator begin()const { return _rb.Begin(); }
		const_iterator end()const { return _rb.End(); }

		pair<iterator, bool> insert(const pair<const K, V>& data)
		{
			return _rb.Insert(data);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return (ret.first)->second;
		}

	private:
		RBTree<pair<const K, V>, KeyofMap<K, V>> _rb;
	};

}

